package com.msmall.plugin.kindeidtor.action;

import java.io.File;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ImageUtil;
import com.msmall.plugin.kindeidtor.service.ImgUploadService;

/**
 * kindeditor图片上传组件
 */
public class ImgUploadAction extends HTMLBaseAction{

	private static final long serialVersionUID = -7560834853368116745L;

	private String id;
	private File imgFile;
	private String imgFileContentType; // 文件的内容类型
	private String imgFileFileName; // 上传文件名
	private String newname;
	private String imgTitle;  
	private String align;  
	private int imgWidth;  
	private int imgHeight;  
	private int imgBorder;
	private String saveUrl;
	public String execute(){
		try{
			String[] fileinfo = ImgUploadService.saveImage(imgFile, imgFileFileName, newname, getUserid(), getUserAgentType());
			saveUrl = "/" + fileinfo[0]+fileinfo[1];
			if(imgWidth ==0 || imgHeight==0){
				int[] wh = ImageUtil.getWidthHeight(saveUrl);
				imgWidth = wh[0];
				imgHeight = wh[1];
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public File getImgFile() {
		return imgFile;
	}
	public void setImgFile(File imgFile) {
		this.imgFile = imgFile;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getImgTitle() {
		return imgTitle;
	}

	public void setImgTitle(String imgTitle) {
		this.imgTitle = imgTitle;
	}

	public String getAlign() {
		return align;
	}

	public void setAlign(String align) {
		this.align = align;
	}

	public int getImgWidth() {
		return imgWidth;
	}

	public void setImgWidth(int imgWidth) {
		this.imgWidth = imgWidth;
	}

	public int getImgHeight() {
		return imgHeight;
	}

	public void setImgHeight(int imgHeight) {
		this.imgHeight = imgHeight;
	}

	public int getImgBorder() {
		return imgBorder;
	}

	public void setImgBorder(int imgBorder) {
		this.imgBorder = imgBorder;
	}

	public String getImgFileContentType() {
		return imgFileContentType;
	}

	public void setImgFileContentType(String imgFileContentType) {
		this.imgFileContentType = imgFileContentType;
	}

	public String getImgFileFileName() {
		return imgFileFileName;
	}

	public void setImgFileFileName(String imgFileFileName) {
		this.imgFileFileName = imgFileFileName;
	}

	public String getNewname() {
		return newname;
	}

	public void setNewname(String newname) {
		this.newname = newname;
	}

	public String getSaveUrl() {
		return saveUrl;
	}

	public void setSaveUrl(String saveUrl) {
		this.saveUrl = saveUrl;
	}
}
